package com.example.demo2.controller;

import com.example.demo2.bean.Goods;
import com.example.demo2.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*",
        methods = {RequestMethod.GET, RequestMethod.OPTIONS, RequestMethod.POST})
public class GoodsController {
    @Autowired
    GoodsService yourBeanService;
    private Object list;

    // 查询一个
    @RequestMapping("/h7/goods/list")
    public Map<String, Object> list(){
        Map<String, Object> map = new HashMap<>();
         List<Goods> list = yourBeanService.list();
        if (list != null) {
            map.put("success", true);
            map.put("msg", "成功");
            map.put("list", list);
        } else {
            map.put("success", false);
            map.put("msg", "失败");
        }
        return map;
    }
    @RequestMapping("/h7/goods/deleteGoods")
    public Map<String, Object> delete(@RequestBody Goods yourBean){
        Map<String, Object> map = new HashMap<>();
        try{
            yourBeanService.deleteById(yourBean.getId());
            map.put("success", true);
            map.put("msg", "成功");
        } catch (Exception e){
            map.put("success", false);
            map.put("msg", "失败");
        }
        return map;
    }

}

